package com.mytijian.openapi.adapter.dianping.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.mytijian.openapi.adapter.dianping.service.DzopenModifybooktimeService;
import com.mytijian.openapi.adapter.dianping.service.DzopenStartbookService;

@Component
public class DzAsyncOrderJob implements SimpleJob{

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private DzopenStartbookService dzopenStartbookService;

	@Autowired
	private DzopenModifybooktimeService dzopenModifybooktimeService;

	
	@Override
	public void execute(ShardingContext shardingContext) {
		
		long begin = System.currentTimeMillis();
		
		try {
			dzopenStartbookService.asyncBook();
		} catch (Exception e) {
			logger.error("[美团点评][异步下单] 任务执行失败", e);
		}
		
		try {
			dzopenStartbookService.asyncNotify();
		} catch (Exception e) {
			logger.error("[美团点评][异步下单回调通知] 任务执行失败", e);
		}
		
		try {
			dzopenModifybooktimeService.asyncModifybooktime();
		} catch (Exception e) {
			logger.error("[美团点评][异步改期] 任务执行失败", e);
		}
		
		try {
			dzopenModifybooktimeService.asyncNotify();
		} catch (Exception e) {
			logger.error("[美团点评][异步改期回调通知] 任务执行失败", e);
		}
		
		long end = System.currentTimeMillis();
		long exetimes = end - begin;

		logger.info("[美团点评][下单改期]定时任务执行时间: {}ms", exetimes);
	}
	
}
